package com.example.climbtest;


import com.viewpagerindicator.TabPageIndicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class ClimbTabActivity extends FragmentActivity {
	 private static final String[] CONTENT = new String[] { "Map","List" };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_climb_tab);
		FragmentPagerAdapter adapter = new ClimbAdapter(getSupportFragmentManager());
		
		CustomViewPager pager = (CustomViewPager) findViewById(R.id.pager);
		pager.setAdapter(adapter);
		
        TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
        indicator.setViewPager(pager);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_climb_tab, menu);
		return true;
	}

	class ClimbAdapter extends FragmentPagerAdapter{
		public ClimbAdapter(FragmentManager fragmentManager)
		{
			super(fragmentManager);
		}
        @Override
        public CharSequence getPageTitle(int position) {
            return CONTENT[position % CONTENT.length].toUpperCase();
        }

        @Override
        public int getCount() {
          return CONTENT.length;
        }
		@Override
		public Fragment getItem (int position) {
			switch (position)
			{
			case 0:
				return MapFragment.newInstance();				
			case 1:
				return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
			}
			return null;
		}
	}
}
